/**僚机图片信息 */
enum GuardType { "escort1_png", "Follow_Plane" };

module Fighter {
	/**
	 * 
	 * 购买僚机页面
	 * by 严皓
	 */
	export class BuyGuardUI extends eui.Component {

		public constructor() {
			super();
			this.skinName = "resource/assets/PlaneE/BuyGuardUI.exml"
			this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
		}
		/**护盾僚机 围绕主机旋转	 */
		public Guard_Plane: eui.Group;
		/**跟随 射击僚机  在主机 两旁 */
		public Follow_Plane: eui.Group;
		/**金币显示*/
		private BuyGuard_MoneyShow: eui.BitmapLabel;
		/**护盾价格 */
		public G_Price: eui.BitmapLabel;
		/**跟随价格 */
		public F_Price: eui.BitmapLabel;		
		/**G的选择 */
		public choose_GuardPlane: eui.Group;
		/**F的选择 */
		public choose_FollowPlane: eui.Group;
		/**金币减少跳出 */
		private SubtitleJumped: Fighter.SubtitleJumped = new Fighter.SubtitleJumped();
		/**购买僚机返回按钮 */
		private BuyGuard_back: eui.Group;
		/**是否返回 */
		public Is_back: boolean;

		public onAddToStage() {	
			this.G_Price.text = GameUtil.PlayerMessage.instance.Guard_PlaneConfig[1].price;
			this.F_Price.text =  GameUtil.PlayerMessage.instance.Guard_PlaneConfig[2].price;
			this.BuyGuard_back.addEventListener(egret.TouchEvent.TOUCH_TAP, this.Close, this);
			this.addEventListener(egret.Event.ENTER_FRAME, this.Show, this);
			this.Guard_Plane.addEventListener(egret.TouchEvent.TOUCH_TAP, this.BuyGuard_Plane, this);
			this.Follow_Plane.addEventListener(egret.TouchEvent.TOUCH_TAP, this.BuyFollow_Plane, this);
		}

		public BuyGuard_Plane() {
			if (GameUtil.PlayerMessage.instance.money >= GameUtil.PlayerMessage.instance.Guard_PlaneConfig[1].price ) {
				GameUtil.PlayerMessage.instance.money -= GameUtil.PlayerMessage.instance.Guard_PlaneConfig[1].price;
				GameUtil.PlayerMessage.instance.isBuyGuard = true;
				if (GameUtil.PlayerMessage.instance.isBuyGuard = false) {
					this.choose_GuardPlane.visible = false;
				}
				this.choose_GuardPlane.visible = true;

				//GameUtil.PlayerMessage.instance.BuyGuardArr.push(GameUtil.PlayerMessage.instance.Guard_PlaneConfig[1].name);
				this.SubtitleJumped.SubtitleJumped(GameUtil.PlayerMessage.instance.Guard_PlaneConfig[1].price, this.Guard_Plane);
				this.addChild(this.SubtitleJumped);
				GameUtil.PlayerMessage.instance.isBuyAroundPlane = true;
			}

		}
		public BuyFollow_Plane() {
			if (GameUtil.PlayerMessage.instance.money >= GameUtil.PlayerMessage.instance.Guard_PlaneConfig[2].price ) {
				GameUtil.PlayerMessage.instance.money -= GameUtil.PlayerMessage.instance.Guard_PlaneConfig[2].price;
				GameUtil.PlayerMessage.instance.isBuyGuard = true;
				if (GameUtil.PlayerMessage.instance.isBuyGuard = false) {
					this.choose_FollowPlane.visible = false;
				}
				this.choose_FollowPlane.visible = true;

				//GameUtil.PlayerMessage.instance.BuyGuardArr.push(GameUtil.PlayerMessage.instance.Guard_PlaneConfig[2].name);
				this.SubtitleJumped.SubtitleJumped(GameUtil.PlayerMessage.instance.Guard_PlaneConfig[2].price, this.Follow_Plane);
				this.addChild(this.SubtitleJumped);
				GameUtil.PlayerMessage.instance.isBuyFollowPlane = true;
			}
		}

		private Close() {
			this.Is_back = true;
		}
		/**每帧更新提示信息*/
		public Show() {
			this.BuyGuard_MoneyShow.text =  GameUtil.PlayerMessage.instance.money.toString();
			if (GameUtil.PlayerMessage.instance.isBuyAroundPlane == false) {
				this.choose_GuardPlane.visible = false;

			}
			if (GameUtil.PlayerMessage.instance.isBuyFollowPlane == false) {
				this.choose_FollowPlane.visible = false;
			}


		}
	}
}